//
//  TransDataController.m
//  block
//
//  Created by 李伟 on 16/1/23.
//  Copyright © 2016年 李伟. All rights reserved.
//

#import "TransDataController.h"

@interface TransDataController ()

@property(nonatomic,strong)UITextField *textField;

@end

@implementation TransDataController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1];
    
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 350, 100, 40)];
    
    textField.backgroundColor = [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1];
    
    [self.view addSubview:textField];
    
    self.textField = textField;
    
    // block传值
    SEL block = @selector(block);
    [self createBtn:@"block传值" andFrame:CGRectMake(210, 200, 80, 60) andSelector:block];

}

// 创建按钮
- (void)createBtn:(NSString *)title andFrame:(CGRect)frame andSelector:(SEL)selector{
    
    UIButton *deleBtn = [[UIButton alloc] initWithFrame:frame];
    
    deleBtn.backgroundColor = [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1];
    
    [deleBtn setTitle:title forState:UIControlStateNormal];
    
    [self.view addSubview:deleBtn];
    
    [deleBtn addTarget:self action:selector forControlEvents:UIControlEventTouchUpInside];
    
}

// block传值
- (void)block{
    
    if (self.myBlock) {
        
        self.myBlock(self.textField.text);
        
        [self.navigationController popViewControllerAnimated:YES];
        
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
